<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // toString  转字符串
        var a = 123;
        console.log(typeof a.toString());
        var b = true;
        console.log(typeof b.toString());
        console.log(b.toString());

        // null ,undefined 没有toString方法
        var c = null;
        // console.log(c.toString());  //报错

        // 通过String() 函数转成字符串
        c = String(c);
        console.log(typeof c);
        console.log(c);

        // Number 转数字
        var d = "123";
        d = Number(d);
        console.log(typeof d);
        console.log(d);
        //非数字字符转数字
        var e = "abc";
        e = Number(e);
        console.log(typeof e);
        console.log(e); // NaN
        // 空字符转数字
        var f = " ";
        f = Number(f);
        console.log(typeof f);
        console.log(f); // 0

        // 布尔转数字 : true 1,  false 0
        var g = false;
        g = Number(g);
        console.log(typeof g);
        console.log(g); // 0

        // Null转数字 : 0
        
        // Undefined 转数字 : NaN

        // parseInt 可以将字符中的有效整数内容取出来，转成数字
        var h = "123px";
        h = parseInt(h);
        console.log(h); //123
        var h1 = "123px45";
        h1 = parseInt(h1);
        console.log(h1); // 123
        var h2 = "a123px45";
        h2 = parseInt(h2);
        console.log(h2); // NaN

        // parseFloat 可以将字符中的有效整数和小数内容取出来，转成数字

        console.log(parseInt(true)); // NaN
        console.log(parseInt(198.23)); //198


        // 0x 开头的是16进制数字 
        //0 开头是8进制
        var i = 0xabc;
        i = 070;
        console.log(i);
    </script>
</body>

</html>